﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace okshipper
{
    public static class OpenKeyVerifier
    {
        public Dictionary<string, string> VerifyKeyFile(string key)
        {
            Guardian.DecryptFile("keyfile.elf", "keyfile.tmp", key);
            BinaryReader r = new BinaryReader(File.OpenRead("keyfile.tmp"));
            if (r.ReadString() != "OpenKeyFile")
                return null;

            Dictionary<string, string> result = new Dictionary<string, string>();
            int count = r.ReadInt32();

            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                    result.Add(r.ReadString(), r.ReadString());
            }
            else
            {
                result.Add("empty", "empty");
            }

            r.Close();
            File.Delete("keyfile.tmp");
            return result;
        }
    }
}
